<?php
namespace Api\Controller;
use Think\Controller;

class  MovieController extends BaseController {

   private $m = NULL;
   private $md = NULL;
   private $navName = '订单管理';


   public function _initialize(){
   		parent::_initialize();
		$this->m = M('shop');
		$this->md = M('shop_detail');
		
		
   }
    	 	
	/**   聚餐美食-猜你喜欢  liuq
	*
	*/	
  
   public  function slist(){
  
       //$cid = I('cid');//  用户标识  member id
     $page  = I('page');//页码
   
     $data = $this->m->where('shop_level_two = 19  AND buss_status = 2')->page($page.',10')->order('id desc')->select();      
     $count_num = $this->m->where('shop_level_two = 19  AND buss_status = 2')->order('add_time desc')->count();
       foreach( $data as $key => $item){
        $data1[$key]['id'] = $item['id'];
         $data1[$key]['mid'] = $item['mid'];
          $data1[$key]['shop_name'] = $item['shop_name'];
            $data1[$key]['per_consumption'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('per_consumption');
               $data1[$key]['start_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('start_time'); 
                 $data1[$key]['stop_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('stop_time'); 
                    $data1[$key]['address'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('address'); //http://localhost:81/jdrapia/Uploads/1.jpg
                      $data1[$key]['shop_heapic'] = $this->md->where("s_id=".$item['id'])->getField('shop_heapic')?__VUPLOAD__.'shop_heapic/'.$this->md->where("s_id=".$item['id'])->getField('shop_heapic'):""; //店铺头像
              
                 }
           
        returnApiData3('0','成功',$data1, $data2,$data3,$count_num);exit;	         
       
   }
   
   
   
    public  function choice(){
         $page  = I('page');//页码
         $hall_type = I('hall_type');   // 1(60帧厅) 2(IMAX厅)3（RealD厅）4（巨幕厅）5（Real 6FL厅）6（4k厅）7（杜比全景声厅）8（中国巨幕厅）9（4DX厅）10（其他）
        
          if(!empty($hall_type)){
              $where['hall_type'] = $hall_type;
           }
         $data = $this->md->where($where)->page($page.',10')->order('id desc')->select();
         $count_num = $this->md->where($where)->order('id desc')->count();
         foreach ($data as $key => $value) {
           
            $shop_level_two = M('shop')->where("id=".$value['s_id'])->getField('shop_level_two');
            $shop=M('shop')->where("id=".$value['s_id'])->find();
             
            if( $shop_level_two== 19){
                  $string.=$shop['id'].'|';
              }
            
         }
         
          $array=explode("|", $string);
          array_pop($array);
          foreach ($array as $key => $value) {
         $data4[$key]['shop_name'] = $value;
           $data4[$key]['shop_name'] = M('shop')->where('id="'.$value.'"')->getField('shop_name');
              $data4[$key]['per_consumption'] = M('shop_detail')->where('s_id="'.$value.'"')->getField('per_consumption');
                $data4[$key]['start_time'] = M('shop_detail')->where('s_id="'.$value.'"')->getField('start_time'); 
                    $data4[$key]['stop_time'] = M('shop_detail')->where('s_id="'.$value.'"')->getField('stop_time'); 
                      $data4[$key]['address'] = M('shop_detail')->where('s_id="'.$value.'"')->getField('address'); 
                         $data4[$key]['shop_heapic'] = $this->md->where('s_id="'.$value.'"')->getField('shop_heapic')?__VUPLOAD__.'shop_heapic/'.$this->md->where("s_id=".$item['id'])->getField('shop_heapic'):""; //店铺头像
  
           }
           
             returnApiData3('0','成功',$data4, $data2,$data3,$count_num);exit;	
   }
             
   ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   
   
  public  function  five_order(){  //  5  29
     $page  = I('page');//页码
     $order_type  =  I('order_type'); //排序条件  1智能排序   2 离我最近   3 最新发布   4 价格最高  
     
     $data = $this->m->where('shop_level_two = 19 AND buss_status = 2')->page($page.',10')->select();
     $count_num = $this->m->where('shop_level_two = 19  AND buss_status = 2')->order('add_time desc')->count();
              
     if( $order_type == 1){
         foreach( $data as $key => $item){
           $data[$key]['per_consumption'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('per_consumption');
              $data[$key]['start_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('start_time'); 
                $data[$key]['stop_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('stop_time'); 
                   $data[$key]['address'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('address'); //http://localhost:81/jdrapia/Uploads/1.jpg
                     $data[$key]['shop_heapic'] = $this->md->where("s_id=".$item['id'])->getField('shop_heapic')?__VUPLOAD__.'shop_heapic/'.$this->md->where("s_id=".$item['id'])->getField('shop_heapic'):""; //店铺头像
                }
                 
                   foreach($data as $v){  
                      $flag[] = $v['add_time'];  
                   }  
                   array_multisort($flag, SORT_ASC, $data); 
                   
               }
               
               
               
    if( $order_type == 3){
                    
         foreach( $data as $key => $item){
           $data[$key]['per_consumption'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('per_consumption');
              $data[$key]['start_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('start_time'); 
                $data[$key]['stop_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('stop_time'); 
                   $data[$key]['address'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('address'); //http://localhost:81/jdrapia/Uploads/1.jpg
                     $data[$key]['shop_heapic'] = $this->md->where("s_id=".$item['id'])->getField('shop_heapic')?__VUPLOAD__.'shop_heapic/'.$this->md->where("s_id=".$item['id'])->getField('shop_heapic'):""; //店铺头像
                }
                 
                   foreach($data as $v){  
                      $flag[] = $v['add_time'];  
                   }  
                   array_multisort($flag, SORT_DESC, $data); 
                
                }
              
                
                
     if($order_type == 4){
        foreach( $data as $key => $item){
           $data[$key]['per_consumption'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('per_consumption');
              $data[$key]['start_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('start_time'); 
                $data[$key]['stop_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('stop_time'); 
                   $data[$key]['address'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('address'); //http://localhost:81/jdrapia/Uploads/1.jpg
                     $data[$key]['shop_heapic'] = $this->md->where("s_id=".$item['id'])->getField('shop_heapic')?__VUPLOAD__.'shop_heapic/'.$this->md->where("s_id=".$item['id'])->getField('shop_heapic'):""; //店铺头像
                }
                  foreach($data as $v){  
                         $flag[] = $v['per_consumption'];  
                   }  
                  array_multisort($flag, SORT_DESC, $data); 
        }
        
       // dump($data);exit;
     returnApiData3('0','成功',$data, $data2,$data3,$count_num);exit;	
               
               
   }
   

           public  function  shop_detail(){
                   $mid = I('mid');
                   $shop_id = $this->m->where('mid="'.$mid.'"')->getField('id');
                   $dataInfo = $this->md->where('s_id="'.$shop_id.'"')->find();
                   $data['mid'] = $mid;
                   $data['shop_toppics']  =  $dataInfo['shop_toppics']?__VUPLOAD__.'shop_toppics/'.$dataInfo['shop_toppics']:"";
                   $data['shop_heapic']  =  $dataInfo['shop_heapic']?__VUPLOAD__.'shop_heapic/'.$dataInfo['shop_heapic']:"";
                   $data['shop_name'] = M('shop')->where('mid="'.$mid.'"')->getField('shop_name');
                   $data['shop_intro'] = M('shop')->where('mid="'.$mid.'"')->getField('shop_intro');    
                   $data['address'] = M('shop_detail')->where('s_id="'.$shop_id.'"')->getField('address'); 
                   $data['shop_intropics'] = $dataInfo['shop_intropics'];  
                   $data['per_consumption'] = $dataInfo['per_consumption'];   
                   $data['telephone'] = M('shop_detail')->where('s_id="'.$shop_id.'"')->getField('telephone');  
                  // $data['class_name'] = M('shop_product_class')->where('id="'.$dataInfo['shop_level_three'].'"')->getField('class_name');
                       
                   $attitude = M('shop_evaluate')->where('mid="'.$mid.'"')->sum('attitude_star'); 
                   $speed = M('shop_evaluate')->where('mid="'.$mid.'"')->sum('speed_star'); 
                   $taste = M('shop_evaluate')->where('mid="'.$mid.'"')->sum('taste_star'); 
                   $evaluate_times = M('shop_evaluate')->where('mid="'.$mid.'"')->count();
                   $comment_star = round(( $attitude  + $speed + $taste )/( $evaluate_times*3 ));  
                   $data['comment_star_num'] = $comment_star;
                    
                   if(  $comment_star == 1 ){
                      $data['comment_star_value'] = __VUPLOAD__.'evaluate/'."1star.png";
                   }elseif(   $comment_star == 2  ){
                      $data['comment_star_value'] = __VUPLOAD__.'evaluate/'."2star.png";
                   }elseif(   $comment_star == 3  ){
                      $data['comment_star_value'] = __VUPLOAD__.'evaluate/'."3star.png";
                   }elseif(   $comment_star == 4  ){
                      $data['comment_star_value'] = __VUPLOAD__.'evaluate/'."4star.png";
                   }elseif(   $comment_star == 5  ){
                      $data['comment_star_value'] = __VUPLOAD__.'evaluate/'."5star.png";
                   }else{
                      $data['comment_star_value'] = __VUPLOAD__.'evaluate/'."6star.png";
                   }
                   
                   
                   
                  $mid_movie = M('shop_movie')->where('mid="'.$mid.'"')->order('add_time  desc')->select();
                  foreach ( $mid_movie  as $key => $value){
                      $data2[$key]['mov_name'] = $value['mov_name'];
                      $data2[$key]['mov_pic'] = $value['mov_pic']?__VUPLOAD__.'mov_pic/'.$value['mov_pic']:""; //电影头像
                   }
                  
                   returnApiData2('0','成功',$data, $data2,$data3);exit;	
           }
           
           
       public  function  mov_type_1(){  //热映
             $mid = I('mid');
             $page  = I('page');//页码
             $data = M('shop_movie')->where('mid="'.$mid.'" AND mov_type = 1')->page($page.',10')->select();
             $count_num = $this->m->where('mid="'.$mid.'" AND mov_type = 1')->order('add_time desc')->count();
            foreach($data as $key => $item){
                $info[$key]['id'] = $item['id'];
                $info[$key]['mov_name'] = $item['mov_name'];
                $info[$key]['show_time'] = date("Y-m-d", $item['show_time']);
                $info[$key]['start_price'] = $item['start_price'];
                $info[$key]['stop_price'] = $item['stop_price'];
                $info[$key]['mov_pic'] = $item['mov_pic']?__VUPLOAD__.'mov_pic/'.$item['mov_pic']:""; //电影头像
                $msg = M('shop_movie_detail')->where('mv_id="'.$info[$key]['id'].'"')->select();
                foreach( $msg as $key1 => $item1){
                    $info[$key]['play_time'][$key1] = date("Y-m-d", $item1['play_time']).'----'. date("h:i", $item1['start_time']).'-'.date("h:i", $item1['stop_time']);
                    if( $item1['hall_type'] == 1){ //1(60帧厅) 2(IMAX厅)3（RealD厅）4（巨幕厅）5（Real 6FL厅）6（4k厅）7（杜比全景声厅）8（中国巨幕厅）9（4DX厅）10（其他）
                      $info[$key]['hall_type'][$key1]  = '60帧厅';
                    }elseif ( $item1['hall_type'] == 2) {
                      $info[$key]['hall_type'][$key1]  = 'IMAX厅';
                    } elseif ($item1['hall_type'] == 3) {
                      $info[$key]['hall_type'][$key1]  = 'RealD厅';
                    }elseif ($item1['hall_type'] == 4) {
                      $info[$key]['hall_type'][$key1]  = '巨幕厅';
                    }elseif($item1['hall_type'] == 5){
                      $info[$key]['hall_type'][$key1]  = 'Real 6FL厅';
                    }elseif($item1['hall_type'] == 6){
                      $info[$key]['hall_type'][$key1]  = '4k厅';
                    } elseif ($item1['hall_type'] == 7) {
                      $info[$key]['hall_type'][$key1]  = '杜比全景声厅';
                    }elseif($item1['hall_type'] == 8){
                      $info[$key]['hall_type'][$key1]  = '中国巨幕厅';
                    }elseif($item1['hall_type'] == 9){
                      $info[$key]['hall_type'][$key1]  = '4DX厅';
                    }elseif($item1['hall_type'] == 10){
                      $info[$key]['hall_type'][$key1]  = '其他';
                    }
                    
                }
            } 
               returnApiData3('0','成功',$info, $data2,$data3,$count_num);exit;
       }
           
       
       
         public  function  mov_type_2(){  //热映
            $mid = I('mid');
            $page  = I('page');//页码
            $data = M('shop_movie')->where('mid="'.$mid.'" AND mov_type = 2')->page($page.',10')->select();
            $count_num = $this->m->where('mid="'.$mid.'" AND mov_type = 2')->order('add_time desc')->count();
            foreach($data as $key => $item){
                $info[$key]['id'] = $item['id'];
                $info[$key]['mov_name'] = $item['mov_name'];
                $info[$key]['show_time'] = date("Y-m-d", $item['show_time']);
                $info[$key]['start_price'] = $item['start_price'];
                $info[$key]['stop_price'] = $item['stop_price'];
                $info[$key]['mov_pic'] = $item['mov_pic']?__VUPLOAD__.'mov_pic/'.$item['mov_pic']:""; //电影头像
                $msg = M('shop_movie_detail')->where('mv_id="'.$info[$key]['id'].'"')->select();
                foreach( $msg as $key1 => $item1){
                    $info[$key]['play_time'][$key1] = date("Y-m-d", $item1['play_time']).'----'. date("h:i", $item1['start_time']).'-'.date("h:i", $item1['stop_time']);
                    if( $item1['hall_type'] == 1){ //1(60帧厅) 2(IMAX厅)3（RealD厅）4（巨幕厅）5（Real 6FL厅）6（4k厅）7（杜比全景声厅）8（中国巨幕厅）9（4DX厅）10（其他）
                      $info[$key]['hall_type'][$key1]  = '60帧厅';
                    }elseif ( $item1['hall_type'] == 2) {
                      $info[$key]['hall_type'][$key1]  = 'IMAX厅';
                    } elseif ($item1['hall_type'] == 3) {
                      $info[$key]['hall_type'][$key1]  = 'RealD厅';
                    }elseif ($item1['hall_type'] == 4) {
                    $info[$key]['hall_type'][$key1]  = '巨幕厅';
                    }elseif($item1['hall_type'] == 5){
                      $info[$key]['hall_type'][$key1]  = 'Real 6FL厅';
                    }elseif($item1['hall_type'] == 6){
                      $info[$key]['hall_type'][$key1]  = '4k厅';
                    } elseif ($item1['hall_type'] == 7) {
                     $info[$key]['hall_type'][$key1]  = '杜比全景声厅';
                    }elseif($item1['hall_type'] == 8){
                    $info[$key]['hall_type'][$key1]  = '中国巨幕厅';
                    }elseif($item1['hall_type'] == 9){
                        $info[$key]['hall_type'][$key1]  = '4DX厅';
                    }elseif($item1['hall_type'] == 10){
                         $info[$key]['hall_type'][$key1]  = '其他';
                    }
                    
                }
            } 
               returnApiData3('0','成功',$info, $data2,$data3,$count_num);exit;
       }
           
           
    public function   price_order(){
        
         $from_money = I('from_money');
         $to_money = I('to_money');
//         $from_money = 18;
//         $to_money = 65;
         if($from_money){
		$where['per_consumption']= array('EGT',$from_money);
	 }
	if($to_money){
		$where['per_consumption']= array('ELT',$to_money);
         }		
		
       if($from_money && $to_money){
	        $where['per_consumption']=array(array('EGT',$from_money),array('ELT',$to_money),'and');
        }	
        
     // $this->m->where('(shop_level_two = 8  OR  shop_level_two = 32)  AND buss_status = 2')->select();
        $data = $this->md->where($where)->order('id desc')->select();
        
        
         foreach ($data as $key => $value) {
           
            $shop_level_two = M('shop')->where("id=".$value['s_id'])->getField('shop_level_two');
            $shop=M('shop')->where("id=".$value['s_id'])->find();
             
            if( $shop_level_two== 5 || $shop_level_two == 29){
                  $string.=$shop['id'].'|';
           
              }
            
         }
         
          $array=explode("|", $string);
          array_pop($array);
          foreach ($array as $key => $value) {
           $data4[$key]['shop_name'] = M('shop')->where('id="'.$value.'"')->getField('shop_name');
              $data4[$key]['per_consumption'] = M('shop_detail')->where('s_id="'.$value.'"')->getField('per_consumption');
                $data4[$key]['start_time'] = M('shop_detail')->where('s_id="'.$value.'"')->getField('start_time'); 
                    $data4[$key]['stop_time'] = M('shop_detail')->where('s_id="'.$value.'"')->getField('stop_time'); 
                      $data4[$key]['address'] = M('shop_detail')->where('s_id="'.$value.'"')->getField('address'); 
                         $data4[$key]['shop_heapic'] = $this->md->where('s_id="'.$value.'"')->getField('shop_heapic')?__VUPLOAD__.'shop_heapic/'.$this->md->where("s_id=".$item['id'])->getField('shop_heapic'):""; //店铺头像
  
           }
           // dump($data4);exit;
            returnApiData2('0','成功',$data4, $data2,$data3);exit;
        
      }
      
    
    
   
      
     

}